#ifndef PARAMETERMODEL_H
#define PARAMETERMODEL_H

#include <QAbstractListModel>
#include "parameteritem.h"

class ParameterModel : public QAbstractListModel
{
    Q_OBJECT
public:
    explicit ParameterModel(QObject *parent = nullptr);
    ~ParameterModel() override;

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;

    Q_INVOKABLE void addItem(ParameterItem *item);
    Q_INVOKABLE void removeByIndex(int index);
    Q_INVOKABLE ParameterItem *itemAt(int index);
    Q_INVOKABLE int count() const { return m_itemList.count(); }
    Q_INVOKABLE void clear();
    Q_INVOKABLE ParameterItem* get(int index) { return itemAt(index); }
    Q_INVOKABLE void copyModel(ParameterModel *model);
    Q_INVOKABLE void freshData();

signals:
    void modelDataUpdated();  // 用于通知QML数据已更新

private:
    QList<ParameterItem *> m_itemList;
};

#endif // PARAMETERMODEL_H
